﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FTBS.Models.BLO;

namespace FTBS.Controllers
{
    public class UserController : Controller
    {
        //
        // GET: /User/
        private UserBLO _userBlo = new UserBLO();

        public ActionResult ChangePassword()
        {
            if (this.Session["RoleName"] == null || this.Session["UserName"] == null || this.Session["Account"] == null || this.Session["RoleName"].ToString().Trim() == "Customer")
            {
                return Redirect("/Home/Announcement");
            }
            return View();
        }

        public string SubmitChangePassword(string oldPass, string newPass)
        {
            if (this.Session["UserName"] != null)
            {
                String oPass = _userBlo.GenerateMD5(oldPass);
                String password = _userBlo.LoadUserByUserName(this.Session["UserName"].ToString().Trim()).Password;
                if (oPass == password)
                {
                    String nPass = _userBlo.GenerateMD5(newPass);
                    if (_userBlo.ChangePassword(this.Session["UserName"].ToString().Trim(), nPass))
                    {
                        return "changeSuccessful";
                    }
                    return "NotSuccessful";
                }
                return "Fail";
            }
            return "SessionTimeOut";
        }
    }
}
